package com.ruoyi.project.wf.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wf.domain.WfProcessActRoleRel;
import com.ruoyi.project.wf.service.IWfProcessActRoleRelService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 流程项角色关系Controller
 *
 * @author XQ.XU
 * @date 2020-04-08
 */
@Controller
@RequestMapping("/wf/wfProcessActRoleRel")
public class WfProcessActRoleRelController extends BaseController
{
    private String prefix = "wf/wfProcessActRoleRel";

    @Autowired
    private IWfProcessActRoleRelService wfProcessActRoleRelService;

    @RequiresPermissions("wf:wfProcessActRoleRel:view")
    @GetMapping()
    public String wfProcessActRoleRel()
    {
        return prefix + "/wfProcessActRoleRel";
    }

    /**
     * 查询流程项角色关系列表
     */
    @RequiresPermissions("wf:wfProcessActRoleRel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WfProcessActRoleRel wfProcessActRoleRel)
    {
        startPage();
        List<WfProcessActRoleRel> list = wfProcessActRoleRelService.list(new QueryWrapper<>(wfProcessActRoleRel));
        return getDataTable(list);
    }

    /**
     * 导出流程项角色关系列表
     */
    @RequiresPermissions("wf:wfProcessActRoleRel:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WfProcessActRoleRel wfProcessActRoleRel)
    {
        List<WfProcessActRoleRel> list = wfProcessActRoleRelService.list(new QueryWrapper<>(wfProcessActRoleRel));
        ExcelUtil<WfProcessActRoleRel> util = new ExcelUtil<WfProcessActRoleRel>(WfProcessActRoleRel.class);
        return util.exportExcel(list, "wfProcessActRoleRel");
    }

    /**
     * 新增流程项角色关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存流程项角色关系
     */
    @RequiresPermissions("wf:wfProcessActRoleRel:add")
    @Log(title = "流程项角色关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WfProcessActRoleRel wfProcessActRoleRel)
    {
        return toAjax(wfProcessActRoleRelService.saveOrUpdate(wfProcessActRoleRel));
    }

    /**
     * 修改流程项角色关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WfProcessActRoleRel wfProcessActRoleRel = wfProcessActRoleRelService.getById(id);
        mmap.put("wfProcessActRoleRel", wfProcessActRoleRel);
        return prefix + "/edit";
    }

    /**
     * 修改保存流程项角色关系
     */
    @RequiresPermissions("wf:wfProcessActRoleRel:edit")
    @Log(title = "流程项角色关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WfProcessActRoleRel wfProcessActRoleRel)
    {
        return toAjax(wfProcessActRoleRelService.saveOrUpdate(wfProcessActRoleRel));
    }

    /**
     * 删除流程项角色关系
     */
    @RequiresPermissions("wf:wfProcessActRoleRel:remove")
    @Log(title = "流程项角色关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wfProcessActRoleRelService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
